package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.coupon.CouponListPageVo;
import net.pinnoocle.playdao.entity.shopPc.coupon.CouponListSearchParams;
import net.pinnoocle.playdao.entity.shopPc.master.CheckOpenScriptPageVo;
import net.pinnoocle.playdao.entity.shopPc.master.OpenScriptDetailVo;
import net.pinnoocle.playdao.entity.shopPc.master.OpenScriptSearchListVo;
import net.pinnoocle.playdao.entity.shopPc.master.UpdateOpenScriptParams;
import net.pinnoocle.playdao.entity.web.master.WebMasterScriptListPage;
import net.pinnoocle.playservice.service.impl.MasterOpenScriptServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ye
 * @Description
 * @create 2021-11-09 11:08
 */
@RestController
@RequestMapping("/open")
@Api(tags = "开本管理")
public class CheckOpenScriptController {

    @Autowired
    MasterOpenScriptServiceImpl openScriptService;

    @GetMapping("openScripts")
    @ApiOperation("开本审核列表")
    public BaseResult<PageModel<CheckOpenScriptPageVo>> couponList(OpenScriptSearchListVo params){
        return new BaseResult<PageModel<CheckOpenScriptPageVo>>().ok(openScriptService.openScripts(params));
    }

    @GetMapping("scriptDetail")
    @ApiOperation("开本审核详情")
    public BaseResult<OpenScriptDetailVo> scriptDetail(@RequestParam("openId") String openId){
        return new BaseResult<OpenScriptDetailVo>().ok(openScriptService.scriptDetail(openId));
    }

    @PostMapping("updateOpenScript")
    @ApiOperation("开本编辑")
    public BaseResult<String> updateOpenScript(@Validated @RequestBody UpdateOpenScriptParams params){
        boolean result = openScriptService.updateOpenScript(params);
        if(result){
            return new BaseResult<String>().success("开本编辑成功");
        }
        return new BaseResult<String>().error("开本编辑失败");
    }

    @GetMapping("checkOpenScript")
    @ApiOperation("开本审核---1 审核通过 2拒绝")
    public BaseResult<String> checkOpenScript(@RequestParam("openId") String openId,
                                              @RequestParam("isCheck") Integer isCheck,
                                              @RequestParam(name = "refuseReason",required = false) String refuseReason){
        boolean result = openScriptService.checkOpenScript(openId,isCheck,refuseReason);
        if(result){
            return new BaseResult<String>().success("开本审核成功");
        }
        return new BaseResult<String>().error("开本审核失败");
    }
}
